package com.hmall.user.controller;

import com.hmall.common.domain.R;
import com.hmall.user.domain.dto.AddRoleDTO;
import com.hmall.user.domain.dto.SetRolePermissionsDTO;
import com.hmall.user.domain.dto.UpdateRoleDTO;
import com.hmall.user.service.SysRolePermissionsService;
import com.hmall.user.service.SysRolesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/*********************************************************
 ** 角色管理controller
 ** <br><br>
 ** @ClassName: RoleController
 ** @author: yangfeng
 ** @date: 2024/12/18 10:18
 ** @version: 1.0.0
 *********************************************************/
@RestController
@Slf4j
@RequestMapping("/role")
@RequiredArgsConstructor
public class RoleController {
    private final SysRolesService rolesService;

    private final SysRolePermissionsService sysRolePermissionsService;

    @PostMapping(value = "/add",name = "新增角色")
    public R<Boolean> add(@RequestBody AddRoleDTO dto){
        return R.ok(rolesService.addRole(dto));
    }
    @PutMapping(value = "/update",name = "更新角色信息")
    public R<Boolean> update(@RequestBody UpdateRoleDTO dto){
        return R.ok(rolesService.updateRole(dto));
    }
    /**
     * 设置角色对应的权限
     * @param dto
     * @Return: com.hmall.common.domain.R<java.lang.Boolean>
     * @author: yangfeng
     * @date: 2024/12/27 15:40
     **/
    @PostMapping(value = "/setPermissions",name = "设置角色对应的权限")
    public R<Boolean> setPermissions(@RequestBody SetRolePermissionsDTO dto){
        return R.ok(sysRolePermissionsService.setPermissions(dto));
    }
}
